# main.py

#-------------------- USER START ------------------------
window = (230, 230)
#--------------------  USER END  ------------------------

import sensor, image, time
from pyb import UART

sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QVGA)
sensor.set_windowing(window)
sensor.skip_frames(time = 2000)
uart = UART(3, 115200)

template = image.Image("template.pgm")

while(True):
    img = sensor.snapshot()
    roi = img.find_template(template, 0.7)
    if(roi != None):
        data = bytearray([roi[0] + int(roi[2] / 2), roi[1] + int(roi[3] / 2), 0xFF])
        uart.write(data)
